//
//  YGGoodsCommentCell.m
//  SunshineMall
//
//  Created by 张艳江 on 2018/10/24.
//  Copyright © 2018年 张艳江. All rights reserved.
//

#import "SCGoodsCommentCell.h"

@implementation SCGoodsCommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpUI];
        [self setUpFrame];
    }
    return self;
}
- (void)setUpUI{
    
    self.portraitImage = [UIImageView new];
    
    self.nameLab = [UILabel new];
    self.nameLab.font = SCFont(15);
    self.nameLab.textColor = [UIColor blackColor];
    
    self.starEvaluator = [StarEvaluator new];
    self.starEvaluator.userInteractionEnabled = NO;
    
    self.dateLabel = [UILabel new];
    self.dateLabel.font = SCFont(12);
    self.dateLabel.textAlignment = NSTextAlignmentLeft;
    self.dateLabel.textColor = [UIColor darkGrayColor];
    
    self.detailLab = [UILabel new];
    self.detailLab.font = SCFont(14);
    self.detailLab.textColor = [UIColor blackColor];
    
    self.picContainerView = [SDWeiXinPhotoContainerView new];
    
    self.lineView = [UIView new];
    self.lineView.backgroundColor = BGColor;
    
    [self.contentView sd_addSubviews:@[self.portraitImage,self.dateLabel,self.nameLab,self.starEvaluator,self.detailLab,self.picContainerView,self.lineView]];
}
- (void)setUpFrame{
    
    self.portraitImage.sd_layout
    .leftSpaceToView(self.contentView, 15)
    .topSpaceToView(self.contentView, 15)
    .widthIs(40)
    .heightEqualToWidth();
    self.portraitImage.clipsToBounds = YES;
    self.portraitImage.layer.cornerRadius = 20.0f;
    
    self.nameLab.sd_layout
    .topEqualToView(self.portraitImage)
    .leftSpaceToView(self.portraitImage, 8)
    .heightIs(17);
    [self.nameLab setSingleLineAutoResizeWithMaxWidth:180];
    
    self.starEvaluator.sd_layout
    .leftSpaceToView(self.nameLab, 8)
    .centerYEqualToView(self.nameLab)
    .widthIs(75)
    .heightIs(18);
    
    self.dateLabel.sd_layout
    .leftEqualToView(self.nameLab)
    .topSpaceToView(self.nameLab, 8)
    .rightSpaceToView(self.contentView, 15)
    .heightIs(17);
    
    self.detailLab.sd_layout
    .topSpaceToView(self.portraitImage, 15)
    .leftSpaceToView(self.contentView, 15)
    .rightSpaceToView(self.contentView, 15)
    .autoHeightRatio(0);
    
    self.picContainerView.sd_layout
    .topSpaceToView(self.detailLab, 15)
    .leftSpaceToView(self.contentView, 15)
    .rightEqualToView(self.dateLabel);
    
    self.lineView.sd_layout
    .topSpaceToView(self.picContainerView, 15)
    .leftSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(8);
}
- (void)setModel:(SCModel *)model{
    
    _model = model;
    
    [self.portraitImage sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@""]];
    self.nameLab.text = model.nickname;
    self.starEvaluator.currentValue = [model.score floatValue];
    self.dateLabel.text = [MyTool getTimeFromTimesTamp:model.add_time];
    self.detailLab.text = model.content;
    NSMutableArray *picMut = [NSMutableArray array];
    for (NSString *picStr in model.pic) {
        [picMut addObject:[NSString stringWithFormat:@"%@%@",Evaluate_ImageURL,picStr]];
    }
    self.picContainerView.picPathStringsArray = [picMut copy];
    
    [self setupAutoHeightWithBottomViewsArray:@[self.lineView] bottomMargin:0];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
